package com.twu.biblioteca;

import java.util.ArrayList;

public class BibliotecaApp {

    ArrayList<Book> bookArray = new ArrayList<Book>();
    ArrayList<Movie> movieArray = new ArrayList<Movie>();
    ArrayList<User> userArray = new ArrayList<User>();

    public void addBook(Book book) {
        bookArray.add(book);
    }

    public void addMovie(Movie movie) {
        movieArray.add(movie);
    }

    public void addUser(User user) {
        userArray.add(user);
    }

    public String listBooks() {
        String output = "";

        Integer i = 0;
        for (Book book : bookArray) {
            output = output + (i + 1) + "\t" + bookArray.get(i).title + " (" + bookArray.get(i).getStatus() + ")\n";
            i++;
        }
        return output;
    }

    public String selectedBook(String i) {
        int bookIndex = Integer.parseInt(i) - 1;
        boolean reserved = bookArray.get(bookIndex).getReserved();

        if (!reserved) {
            bookArray.get(bookIndex).setReserved(true);
            return "Thank You! Enjoy the book.";
        }
        return "Sorry we don't have that book yet.";
    }

    public String listMovies() {

        System.out.printf("\n%-20s %10s %15s %10s", "Title", "Year",
                "Director", "Rating");

        for (Movie movie : movieArray) {
            System.out.printf("\n%-20s %10d %15s %10s",
                    movie.getTitle(), movie.getYear(),
                    movie.getDirector(), movie.getRating());
        }

        /*
        String output = "Movie\tYear\tDirector\tRating\n";

        for (Movie movie : movieArray) {
            output = output + movie.getTitle() + "\t" + movie.getYear() + "\t" +
                    movie.getDirector() + "\t" + movie.getRating() + "\n";
        }
        return output;     */
        return "";

    }



    public boolean userExists(String userLoginEntry) {
        for (User user : userArray) {
            if (user.getUsername().equals(userLoginEntry)) return true;
        }
        return false;
    }
}
